<template>
    <div class="about">
        <div class="site-content">
            <div class="content-warp">
				<div class="about-me about-info">
				    <section-title id="Guestbook"><span>❤</span>手机号登录</section-title>
				    <div class="info-card">
				        <div class="contactForm">
				            <div class="form-item">
				                <label for="mail">账号</label>
				                <input class="v" v-model="phone" type="email" name="mail" id="mail">
				            </div>
				            <div class="form-item">
				                <label for="content">验证码</label>
				                <input class="v" v-model="code" placeholder="验证码"  id="mail">
				            </div>
				            <div class="form-item">
				                <label></label>
				                <button :disabled="isDisable" @click="getcode()">{{ tips }}</button>
				                <el-button @click="login()"> 登录 </el-button>
				            </div>
				        </div>
				    </div>
				</div>
            </div>
        </div>
    </div>
</template>
<script>
    import sectionTitle from '@/components/section-title'
    import {getTime,getTimeInterval} from '@/utils'
	import { setToken } from '@/utils/auth'
	import { getCode, codeLogin } from '@/api/user'
    export default {
        name: "About",
        data() {
            return {
				tips: '获取验证码',
				isDisable: false,
				phone: '',
				code: ''
            }
        },
        components: {
            // Quote,
            sectionTitle
        },
        methods: {
			// 获取验证码
			async getcode() {
			if (this.phone == '') {
			  alert('输入手机号码不能为空')
			  return
			} else {
			  if (this.isDisable) {
				return
			  } else {
				this.isDisable = true
				let data = await getCode(this.phone)
				alert(data.msg)
				let timer = 120;
				var timeFun = setInterval(() => {
				  --timer;
				  this.tips = timer + "s后重新发送";
				  if (timer == 0) {
					console.log(timer)
					this.tips = "重新发送";
					this.isDisable = false
					clearInterval(timeFun)
				  }
				}, 1000)
			
			  }
			}
			},
			async login() {
				if (this.code == '') {
					alert("验证码不能为空")
					return
				}
				if (this.phone == '') {
					alert('输入手机号码不能为空')
					return
				}
				let data = await codeLogin({
					phone: this.phone,
					code: this.code
				})
				alert("登录成功")
				localStorage.setItem("token", data.token);
				setToken(data.token)
				this.$router.push('/')
			}
		},
        mounted() {
        }
    }
</script>
<style scoped lang="less">
    .about {
        padding-top: 40px;
    }

    .content-warp {
        margin-top: 80px;

        .about-info {
            margin: 30px 0;

            span {
                color: red;
                margin-right: 10px;
            }

            .info-card {
                min-height: 100px;
                padding: 20px;
                border-radius: 3px;
                margin: 30px 0 50px 0;
                box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
                p{
                    line-height: 1.7rem;
                }
            }
        }
        .contactForm{
            width: 100%;
            padding: 20px;
            .form-item{
                align-items: center;
                display: flex;
                &:not(:last-child){
                    margin-bottom: 20px;
                }
                label{
                  width: 80px;
                }
                .v{
                    min-height: 40px;
                    line-height: 20px;
                    border-radius: 3px;
                    padding: 2px 10px;
                    outline:none;
                    border: 1px solid #8fd0cc;
                    width: 100%;
                    resize: vertical;
                }
                button{
                    width: 100px;
                    height: 40px;
                    border-radius: 3px;
                    outline:0;
                    border-style: none;
                    cursor: pointer;
                    background-color: #409eff;
                    color: white;
                    &:hover{
                        opacity: 0.8;
                    }
                }
            }
        }
    }

    /*******/
    @media (max-width: 800px) {
        .content-warp {
            margin-top: 0;
        }
    }
</style>
